<?php

if( $_POST ){
	foreach( $_POST['departments'] as $k => $v ){
		file_get_contents('http://oa.heivr.com/api/qq/cloud/sendBroadcast/?dep_id=' . $v);
	}
}

$datas = file_get_contents('http://oa.heivr.com/api/qq/cloud/dept/list/');
$json = json_decode($datas, true);
$pass = array('研发部', '分公司', '北京分公司');
unset($json['data']['items'][0]);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cui</title>
<style>
#detailtab{width:980px;margin-top:5px;border:1px solid #E8E8E8;font-size:14px;color:#222;}#detailtab .name{width:auto;text-align:left;}#detailtab .price{width:18%;text-align:center;}#detailtab .amount{width:23%;text-align:center;}#detailtab .subtotal{width:18%;text-align:right;}#detailtab caption,#detailtab th,#detailtab td{padding:8px 10px;background:#FFF;border:1px solid #E8E8E8;border-top:none;word-break:break-all;word-wrap:break-word;}#detailtab caption{background:#F0F0F0;}#detailtab caption .title,#detailtab .subline .title{font-weight:bold;}#detailtab th{background:#F0F0F0;font-weight:bold;}#detailtab td{border-left-style:dotted;border-right-style:dotted;border-bottom-style:dotted;}#detailtab .subline{background:#FBFBFB;text-align:center;}#detailtab-summary{padding:2px 10px;text-align:right;}#detailtab-summary .worth{display:inline-block;min-width:50px;_width:50px;word-break:normal;word-wrap:normal;font-weight:bold;}#detailtab-summary .price{color:#ea4f01;}
</style>
</head>

<body>
<div style="margin:0 auto; text-align:center; width:980px;">
<form action="cui.php" method="post">
<table id="detailtab" cellspacing="0" cellpadding="0" border="1">
    <thead>
        <tr>
            <th class="first" valign="center" width="40">选择</th>
            <th width="247" valign="center">
              部门</th>
        </tr>
    </thead>
    <tbody>
<?php
	foreach( $json['data']['items'] as $k => $v ){
		if( !in_array($v['dept_name'], $pass) ){
			echo '<tr>
            <td class="first" valign="center" align="left"><input type="checkbox" name="departments[]" value="'.$v['dept_id'].'" checked="checked" /></td>
            <td align="middle" valign="center">'.$v['dept_name'].'</td>
        </tr>';
		}
	}
?>
    </tbody>
    <tbody>
        <tr>
            <td class="bottom" valign="center" colspan="2"><input name="submit" type="submit" value="催" /></td>
        </tr>
    </tbody>
</table>
</form>
</div>
<?php
if( $_POST ){
	echo "<script>alert('催命成功');</script>";
}
?>
</body>
</html>
